/*
 * @Author: 何丽彬
 * @Email: helibin@yingzi.com
 * @Date: 2021-11-19 09:14:50
 * @LastEditTime: 2021-11-26 14:12:30
 * @LastEditors: 何丽彬
 * @FilePath: \process-learn\多进程\process.js
 */
// 主进程 process.js

console.time("timer");
const fork = require("child_process").fork;
const cpuNum = require("os").cpus().length;
let cnt = cpuNum;
for (let i = 0; i < cpuNum; i++) {
  const worker = fork("./process_child.js");
  worker.send("start");
  worker.on("message", () => {
    if (--cnt === 0) {
      console.timeEnd("timer");
      process.exit(0);
    }
  });
}
